home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows2 / hp22d3.zip / REFGUIDE / MESSAGES.TXT < prev    next >
Text File  |  1991-05-16  |  44KB  |  1,320 lines

  1.  
  2.  
  3.  
  4.  
  5.      _______________________________________________________________________
  6.                                  Chapter 1: What's Really Happening   73
  7.     ________________________________________________________________________
  8.  
  9.  
  10.     CHAPTER TEN: MESSAGES
  11.  
  12.     The following chapter describes in detail all of the messages sent to
  13.     HyperPAD's objects. It is divided into three sections, one for each type
  14.     of object that can initially receive a message. Each section begins with
  15.     a table describing the messages discussed in that section. At the end of
  16.     this chapter is a table of common events that occur in HyperPAD, along
  17.     with the list of messages sent when these events occur.
  18.  
  19.  
  20.     ABOUT MESSAGES
  21.  
  22.     A message is a notification sent to an object indicating that something
  23.     has happened in the HyperPAD system. For example, if you click the mouse
  24.     on a button, the mouseUp message is sent to that button.
  25.     Once sent, a message follows a predetermined path through the object
  26.     hierarchy. The starting point into this path is either a button, field,
  27.     or page.
  28.  
  29.     If the receiving object does not have a handler for a message, the
  30.     message will be passed on to the next object in the hierarchy until
  31.     either a handler is found for that message or it reaches HyperPAD.
  32.  
  33.     There are two types of messages that can be sent to objects. The first
  34.     type is a notification message. This type of message is sent after an
  35.     action has already occurred, and thus notifies the object of the event.
  36.     The second type of message is sent before an action occurs. For example,
  37.     when the user selects the Delete Button command from the Edit menu, the
  38.     deleteButton message is sent to the current button. The button will not
  39.     be deleted until the message has traveled through the object hierarchy
  40.     and is received by HyperPAD.
  41.  
  42.  
  43.  
  44.      _______________________________________________________________________
  45.                                  Chapter 1: What's Really Happening   74
  46.     ________________________________________________________________________
  47.  
  48.  
  49.     MESSAGE SENT FROM COMMANDS
  50.  
  51.     In addition to the messages sent to objects, there are a few messages
  52.     automatically sent by their command counterparts. You can create
  53.     handlers for them. The implementation for these messages is defined in
  54.     HyperPAD itself.
  55.  
  56.     beep
  57.     close
  58.     flushCache
  59.     fxshow
  60.     noSound
  61.     play
  62.     playBack
  63.     record
  64.     setDefaultPopupColors
  65.     setPopupColors
  66.     sound
  67.     wait
  68.  
  69.     You can find descriptions of these commands in Chapter Eleven,
  70.     "Commands."
  71.  
  72.  
  73.     MESSAGES SENT TO A BUTTON
  74.  
  75.     This section lists all of the messages that are initially sent to
  76.     buttons. In other words, a button is a possible entry point into the
  77.     object hierarchy for these messages. If the receiving button does not
  78.     contain a handler for the message, the message will be passed up the
  79.     hierarchy until it reaches a handler for that message. If no handler is
  80.     found, the message will eventually reach HyperPAD.
  81.  
  82.     The following table shows all of the messages sent to buttons. The
  83.     column on the right indicates if the message is sent before or after the
  84.     action occurs (i.e. results in an action when received by HyperPAD).
  85.  
  86.     Message:            Message Type:
  87.     ---------------------------------------------------
  88.     closeButton         after
  89.  
  90.     deleteButton        before
  91.  
  92.     keyPress            before
  93.  
  94.     mouseDown           after
  95.  
  96.     mouseEnter          after
  97.  
  98.     mouseLeave          after
  99.  
  100.  
  101.  
  102.      _______________________________________________________________________
  103.                                  Chapter 1: What's Really Happening   75
  104.     ________________________________________________________________________
  105.  
  106.  
  107.     Message:            Message Type:
  108.     ---------------------------------------------------
  109.     mouseStillDown      after
  110.  
  111.     mouseUp             after
  112.  
  113.     mouseWithin         after
  114.  
  115.     newButton           after
  116.  
  117.     openButton          after
  118.  
  119.     select              after, except with checkBox buttons
  120.  
  121.     -----------------------------------
  122.     CLOSEBUTTON
  123.  
  124.     This message is sent to a button when the focus is removed. A button
  125.     loses the focus when the user moves the cursor by clicking the right
  126.     mouse button outside the button's borders, or by pressing the TAB key or
  127.     arrow keys to move to another object.
  128.  
  129.     The following example uses closeButton and openButton to change the
  130.     border of a button, indicating when the button has the focus.
  131.  
  132.     handler closeButton;
  133.     begin;
  134.       set the edgeType of me to 1;
  135.     end;
  136.  
  137.     handler openButton;
  138.     begin
  139.       set the edgeType of me to 2;
  140.     end;
  141.  
  142.     -----------------------------------
  143.     DELETEBUTTON
  144.  
  145.     The deleteButton message is sent to a button when the user selects Cut
  146.     Button or Delete Button from HyperPAD's menus. When this message reaches
  147.     HyperPAD, the button is deleted. By intercepting the message, you can
  148.     prevent buttons from being deleted.
  149.  
  150.  
  151.  
  152.      _______________________________________________________________________
  153.                                  Chapter 1: What's Really Happening   76
  154.     ________________________________________________________________________
  155.  
  156.  
  157.     For example, the following handler (in a button script) presents the
  158.     user with a dialog box whenever Delete or Cut Button is selected, asking
  159.     them if it is okay to delete the button.
  160.  
  161.     handler deleteButton;
  162.       begin
  163.         answer "Ok to delete button?" with "Yes", "No";
  164.         if it is "Yes" then pass;
  165.       end;
  166.  
  167.     This example passes the message on to HyperPAD (to delete the button)
  168.     only if the user answers "Yes" in the answer dialog box.
  169.  
  170.     -----------------------------------
  171.     KEYPRESS
  172.  
  173.     The keyPress message is sent to the button with the focus when any key
  174.     is pressed.
  175.  
  176.     In the following example, pressing CTRL+ENTER selects the button:
  177.  
  178.     handler keyPress(k);
  179.     begin
  180.       if key(k) is "CTRL+ENTER" then send "select" to me
  181.       else pass;
  182.     end;
  183.  
  184.     -----------------------------------
  185.     MOUSEDOWN
  186.  
  187.     The mouseDown message is sent to the button when the mouse button is
  188.     pressed while the mouse pointer is within the rectangle of the button.
  189.  
  190.     -----------------------------------
  191.     MOUSEENTER
  192.  
  193.     The mouseEnter message is sent to the button when the mouse pointer
  194.     enters the button's borders. The mouse button does not have to be
  195.     pressed for this message to be sent. (See the example under mouseLeave.)
  196.  
  197.     -----------------------------------
  198.     MOUSELEAVE
  199.  
  200.     The mouseLeave message is sent to the button when the mouse pointer
  201.     exits the button's borders. This message will only be sent to objects
  202.     that have first received a mouseEnter message.
  203.  
  204.     An interesting use for mouseEnter and mouseLeave is to highlight the
  205.     button that the mouse pointer is currently on.
  206.  
  207.  
  208.  
  209.      _______________________________________________________________________
  210.                                  Chapter 1: What's Really Happening   77
  211.     ________________________________________________________________________
  212.  
  213.  
  214.     The following handlers in the button script will accomplish this:
  215.  
  216.     handler mouseEnter;
  217.     begin
  218.       set the hilite of me to true;
  219.     end;
  220.  
  221.     handler mouseLeave;
  222.     begin
  223.       set the hilite of me to false;
  224.     end;
  225.  
  226.     -----------------------------------
  227.     MOUSESTILLDOWN
  228.  
  229.     The mouseStillDown message is sent to a button continuously while the
  230.     mouse button is held down. In order for this message to be sent, the
  231.     mouse must have been initially pressed within the rectangle of the
  232.     button.
  233.  
  234.     -----------------------------------
  235.     MOUSEUP
  236.  
  237.     The mouseUp message is sent to a button when the mouse button is
  238.     released and the mouse pointer is within the button's border. The mouse
  239.     pointer must be inside the original button where the mouse button was
  240.     pressed.
  241.  
  242.     -----------------------------------
  243.     MOUSEWITHIN
  244.  
  245.     When the pointer is within the button's rectangle, the mouseWithin
  246.     message is sent continuously. This message is sent after the initial
  247.     mouseEnter message.
  248.  
  249.     -----------------------------------
  250.     NEWBUTTON
  251.  
  252.     This message is sent to a button when it is created, just after it
  253.     appears on-screen. Usually, this message gets passed through the button
  254.     up the object hierarchy unless the button is being pasted and has a
  255.     script with a newButton handler.
  256.  
  257.     The following example handler in the pad script of your Home pad causes
  258.     all new buttons to be colored red and have a double border:
  259.  
  260.     handler newButton;
  261.     begin
  262.       set the edgeType of the target to 2;
  263.       set the color of the target to red;
  264.     end;
  265.  
  266.  
  267.  
  268.      _______________________________________________________________________
  269.                                  Chapter 1: What's Really Happening   78
  270.     ________________________________________________________________________
  271.  
  272.  
  273.     -----------------------------------
  274.     OPENBUTTON
  275.  
  276.     This message is sent to a button when it receives the focus (is
  277.     highlighted). A button receives the focus when the user presses TAB or
  278.     the arrow keys to access it, or clicks a mouse button while the cursor
  279.     is inside the button's border.
  280.  
  281.     The following example handler in a button script causes the button to
  282.     have a double border when it has the focus:
  283.  
  284.     handler openButton;
  285.     begin
  286.       set the edgeType of me to 2;
  287.     end;
  288.  
  289.     -----------------------------------
  290.     SELECT
  291.  
  292.     This message is sent to the button with the focus if you press ENTER,
  293.     SPACE, or click the left mouse button while the cursor is inside the
  294.     button's borders. In other words, this message is sent to a button when
  295.     it is selected. Rather than using mouseUp handlers, create select
  296.     handlers to perform actions when buttons are selected since not every
  297.     HyperPAD user will use the mouse to select buttons.
  298.  
  299.     Below is an example of a button script that uses the select handler:
  300.  
  301.     handler select;
  302.     begin
  303.       go to the next page;
  304.     end;
  305.  
  306.     The select message has special meaning for check box buttons. When the
  307.     user toggles the check of the button (by pressing ENTER or clicking the
  308.     button with the mouse), the select message is sent to that button. When
  309.     the message is received by HyperPAD, the check of the button is toggled.
  310.     By intercepting the select message, you can customize the behavior of
  311.     check box buttons. For example, the following handler in the button
  312.     script prevents  the button's check mark from being changed because the
  313.     message is not passed on to the next object in the hierarchy.
  314.  
  315.     handler Select;
  316.     begin
  317.     end;
  318.  
  319.  
  320.  
  321.      _______________________________________________________________________
  322.                                  Chapter 1: What's Really Happening   79
  323.     ________________________________________________________________________
  324.  
  325.  
  326.     The next example toggles the message box on and off in coordination with
  327.     the check mark of the button:
  328.  
  329.     handler select;
  330.     begin
  331.       set the visible of msg to not the check of me;
  332.       pass;
  333.     end;
  334.  
  335.  
  336.     MESSAGES SENT TO FIELDS
  337.  
  338.     The following messages are initially sent to fields. If the receiving
  339.     field does not contain a handler for the message, the message will be
  340.     passed up the hierarchy until it reaches an appropriate handler. If no
  341.     handler is found, the message will eventually reach HyperPAD.
  342.  
  343.     The column on the right indicates if the message is sent before or after
  344.     the action occurs (i.e. results in an action when received by HyperPAD).
  345.  
  346.     These messages are sent to fields:
  347.  
  348.     Message:            Message Type:
  349.     ---------------------------------------------------
  350.     closeField          after
  351.  
  352.     deleteField         before
  353.  
  354.     keyPress            before
  355.  
  356.     mark                before (for list box fields only)
  357.  
  358.     mouseDown           after
  359.  
  360.     mouseEnter          after
  361.  
  362.     mouseLeave          after
  363.  
  364.     mouseStillDown      after
  365.  
  366.     mouseUp             after
  367.  
  368.     mouseWithin         after
  369.  
  370.     newField            after
  371.  
  372.     openField           after
  373.  
  374.     select              after
  375.  
  376.     unmark              before (for list box fields only)
  377.  
  378.  
  379.  
  380.      _______________________________________________________________________
  381.                                  Chapter 1: What's Really Happening   80
  382.     ________________________________________________________________________
  383.  
  384.  
  385.     -----------------------------------
  386.     CLOSEFIELD
  387.  
  388.     This message is sent to an unlocked field (one that can be edited) when
  389.     the focus is taken away. The focus is removed from a field when it is
  390.     exited by using TAB, the arrow keys, or the mouse. The focus may also be
  391.     changed from within a script.
  392.  
  393.     The following example uppercases the contents of a field when the focus
  394.     is taken away:
  395.  
  396.     handler closeField;
  397.     begin
  398.       put upper(the value of me) into me;
  399.     end;
  400.  
  401.     See Also: openField
  402.  
  403.     -----------------------------------
  404.     DELETEFIELD
  405.  
  406.     The deleteField message is sent when the user selects Cut Field or
  407.     Delete Field from the Edit menu. By intercepting this message, you can
  408.     prevent fields from being deleted.
  409.  
  410.     The following handler in a field's script checks to make sure it is okay
  411.     to delete the field.
  412.  
  413.     handler deleteField;
  414.     begin
  415.       answer "Ok to delete field" && the name of me;
  416.       if it is "Ok" then pass;
  417.     end;
  418.  
  419.     -----------------------------------
  420.     KEYPRESS
  421.  
  422.     The keyPress message is sent to the field with the focus when a key is
  423.     pressed. By intercepting this message, you prevent keys from reaching
  424.     the field or HyperPAD. For example, you can create a field that does not
  425.     allow numbers, as in the following handler:
  426.  
  427.     handler keyPress(keyNum);
  428.     begin
  429.       get key(keyNum);
  430.       if it is not in "1234567890" then pass;
  431.     end;
  432.  
  433.     See Appendix 2, "Key Codes," for details on keyPress key values.
  434.  
  435.  
  436.  
  437.      _______________________________________________________________________
  438.                                  Chapter 1: What's Really Happening   81
  439.     ________________________________________________________________________
  440.  
  441.  
  442.     -----------------------------------
  443.     MARK
  444.  
  445.     The mark message is sent to list box fields when the user attempts to
  446.     mark a line by pressing SPACE or the right mouse button. You can prevent
  447.     lines from being marked by intercepting this message and not passing it.
  448.     The line number being marked is passed as a parameter with this message.
  449.  
  450.     As an example, the following handler keeps track of how many lines are
  451.     marked, allowing a maximum of ten:
  452.  
  453.     handler mark(lineNumber);
  454.     begin
  455.       global numMarked;
  456.       if numMarked < 10 then
  457.         begin
  458.           add 1 to numMarked;
  459.           pass;
  460.         end;
  461.     end;
  462.  
  463.     handler unmark(lineNumber);
  464.     begin
  465.       global numMarked;
  466.       subtract 1 from numMarked;
  467.       pass;
  468.     end;
  469.  
  470.     Note:  See the section on fields in the User's Guide for more
  471.     information on list box fields.
  472.  
  473.     See Also: markerChar, unmark, markerAttr
  474.  
  475.     -----------------------------------
  476.     MOUSEDOWN
  477.  
  478.     The mouseDown message is sent to locked fields (fields that can not be
  479.     edited) when the user presses the left mouse button while the mouse
  480.     pointer is within the field's borders.
  481.  
  482.     -----------------------------------
  483.     MOUSEENTER
  484.  
  485.     This message is sent to a field when the mouse pointer is within the
  486.     rectangle of a field.
  487.  
  488.  
  489.  
  490.      _______________________________________________________________________
  491.                                  Chapter 1: What's Really Happening   82
  492.     ________________________________________________________________________
  493.  
  494.  
  495.     -----------------------------------
  496.     MOUSELEAVE
  497.  
  498.     This message is sent when the mouse pointer exits the boundaries of a
  499.     field.
  500.  
  501.     -----------------------------------
  502.     MOUSESTILLDOWN
  503.  
  504.     The mouseStillDown message is sent to a locked field (uneditable field)
  505.     while the left mouse button is held down. This message will only be sent
  506.     if the mouse was initially pressed within the rectangle of the field.
  507.  
  508.     -----------------------------------
  509.     MOUSEUP
  510.  
  511.     The mouseUp message is sent to a locked field (uneditable field) when
  512.     the left mouse button is released and the mouse pointer is within the
  513.     field's borders. The mouse pointer must be within the same field that
  514.     received the initial mouseDown message.
  515.  
  516.     If you click the mouse on an unlocked text field, the field will be
  517.     given the focus and opened for editing.
  518.  
  519.     -----------------------------------
  520.     MOUSEWITHIN
  521.  
  522.     The mouseWithin message is sent to a field continuously while the mouse
  523.     pointer is within the rectangle of the field.
  524.  
  525.     -----------------------------------
  526.     NEWFIELD
  527.  
  528.     The newField message is sent to a field when it is created, just after
  529.     it appears on-screen. Usually, this message gets passed up the object
  530.     hierarchy unless the field is being pasted and has a script with a
  531.     newField handler.
  532.  
  533.     This handler, which causes all new fields to look like typical database
  534.     fields with the name appearing on the left, belongs in the pad script:
  535.  
  536.     handler newField;
  537.     begin
  538.       set the showName of the target to true;
  539.       set the withEdge of the target to false;
  540.       set the rect of the target to 10,10,30,10;
  541.       set the hiliteIfFocus of the target to true;
  542.     end;
  543.  
  544.  
  545.  
  546.      _______________________________________________________________________
  547.                                  Chapter 1: What's Really Happening   83
  548.     ________________________________________________________________________
  549.  
  550.  
  551.     -----------------------------------
  552.     OPENFIELD
  553.  
  554.     The openField message is sent to an unlocked field (one that can be
  555.     edited) when it receives the focus (opened for editing). A field
  556.     receives the focus when it is entered using TAB, the arrow keys, or the
  557.     mouse. The focus may also be sent to that field from a script or the
  558.     message box.
  559.  
  560.     The following example keeps track of the last time a field was updated:
  561.  
  562.     handler openField;
  563.     begin
  564.       global previous_content;
  565.       put the value of me into previous_content;
  566.     end;
  567.  
  568.     handler closeField;
  569.     begin
  570.       global previous_content;
  571.       if previous_content is not the value of me then
  572.         put date() into field "last updated";
  573.     end;
  574.  
  575.     -----------------------------------
  576.     SELECT
  577.  
  578.     This message is sent to list box fields when the user presses ENTER or
  579.     double clicks the mouse on a line in the field, and it is sent to locked
  580.     fields when the user releases the mouse button. Use this message to
  581.     perform actions when the user selects an item from a list box. For
  582.     example:
  583.  
  584.     handler select;
  585.     begin
  586.       get the currentLine of me;
  587.       get line it of the value of me;
  588.       ask "You have selected" && it;
  589.     end;
  590.  
  591.  
  592.  
  593.      _______________________________________________________________________
  594.                                  Chapter 1: What's Really Happening   84
  595.     ________________________________________________________________________
  596.  
  597.  
  598.     -----------------------------------
  599.     UNMARK
  600.  
  601.     This message is sent to list box fields when the user attempts to unmark
  602.     a line by pressing SPACE or the right mouse button. Prevent lines from
  603.     being unmarked by intercepting this message and not passing it.
  604.  
  605.     The line being unmarked is passed as a parameter.
  606.  
  607.     Examples:
  608.     The following unmark handler prevents the user from unmarking all the
  609.     even lines (if they are marked).
  610.  
  611.     handler unMark(lineNum);
  612.     begin
  613.       if lineNum mod 2 is not zero then pass;
  614.     end;
  615.  
  616.     Note:  See the section on fields in the User's Guide for more
  617.     information on list box fields.
  618.  
  619.     See Also: mark, markerChar, markerAttr
  620.  
  621.  
  622.  
  623.      _______________________________________________________________________
  624.                                  Chapter 1: What's Really Happening   85
  625.     ________________________________________________________________________
  626.  
  627.  
  628.     MESSAGES SENT TO A PAGE
  629.  
  630.     This section describes messages received directly by the page. If the
  631.     receiving page does not contain a handler for the message, the message
  632.     will be passed up the hierarchy to the background and so on until it
  633.     reaches an appropriate handler. If no handler is found, the message will
  634.     eventually reach HyperPAD.
  635.  
  636.     The following table lists all of the messages and indicates if the
  637.     message is sent before or after an action occurs(i.e. results in an
  638.     action when received by HyperPAD).
  639.  
  640.     Message:           Type:            Message:           Type:
  641.     -----------------------------------------------------------------------
  642.     break              after            mouseStillDown     after
  643.  
  644.     cancel             after            mouseUp            after
  645.  
  646.     closePad           after            newBackground      after
  647.  
  648.     closePage          after            newPad             after
  649.  
  650.     deleteBackground   before           newPage            after
  651.  
  652.     deletePad          before           openPad            after
  653.  
  654.     doMenu             before           quit               before
  655.  
  656.     help               before           resume             after
  657.  
  658.     idle               after            startUp            after
  659.  
  660.     keyPress           before           suspend            before
  661.  
  662.     mouseDown          after
  663.  
  664.  
  665.     -----------------------------------
  666.     BREAK
  667.  
  668.     This message is sent to the current page when the user presses
  669.     CTRL+BREAK.
  670.  
  671.     The combination CTRL+BREAK stops the execution of any pending handlers.
  672.     CTRL+BREAK also stops many other processes, including sort, query,
  673.     print, find, import, and export. A break handler can be useful if you
  674.     need to perform any cleanup when one of these tasks is interrupted.
  675.  
  676.  
  677.  
  678.      _______________________________________________________________________
  679.                                  Chapter 1: What's Really Happening   86
  680.     ________________________________________________________________________
  681.  
  682.  
  683.     For example, the following break handler cleans up if a find command was
  684.     interrupted.
  685.  
  686.     This handler belongs in a button script:
  687.  
  688.     handler select;
  689.     begin
  690.       global inFind;
  691.       ask "Find what?";
  692.       if it is empty then exit;
  693.       put true into inFind;
  694.       find it;
  695.       put false into inFind;
  696.     end;
  697.  
  698.     This handler belongs in the page script:
  699.  
  700.     handler break;
  701.     begin
  702.       global inFind;
  703.       if inFind then answer "Find aborted!" with "Ok";
  704.     end;
  705.  
  706.     Comments: Another way to stop the execution of all pending handlers is
  707.     with the exit command:
  708.  
  709.     exit to hyperpad;
  710.  
  711.     See Also: keyPress
  712.  
  713.     -----------------------------------
  714.     CANCEL
  715.  
  716.     The cancel message is sent to the current page when the ESC key is
  717.     pressed. This is used to maintain compatibility with the HyperPAD User
  718.     Interface in which ESC takes you back.
  719.  
  720.     The following example goes Home when the user presses ESC:
  721.  
  722.     handler cancel;
  723.     begin
  724.       go home;
  725.     end;
  726.  
  727.     -----------------------------------
  728.     CLOSEPAD
  729.  
  730.     The closePad message is sent to the current page before the pad is
  731.     closed and disappears. This can happen when the user quits, changes to
  732.     another pad, or runs another program.
  733.  
  734.  
  735.  
  736.      _______________________________________________________________________
  737.                                  Chapter 1: What's Really Happening   87
  738.     ________________________________________________________________________
  739.  
  740.  
  741.     You can use closePad to perform any pad cleanup that may be necessary
  742.     before you leave a pad. The following handler uses that opportunity to
  743.     delete the contents of some fields:
  744.  
  745.     handler closePad;
  746.     begin
  747.       put empty into field "time";
  748.       put empty into field "status";
  749.     end;
  750.  
  751.     See Also: openPad, openPage, closePage
  752.  
  753.     -----------------------------------
  754.     CLOSEPAGE
  755.  
  756.     The closePage message is sent to the current page when you go to another
  757.     page, go to another pad, run another program, or quit HyperPAD.
  758.  
  759.     The following example uses a closePage handler to hide some buttons.
  760.     Next time this page is accessed, the buttons will not be visible:
  761.  
  762.     handler closePage;
  763.     begin
  764.       set the lockScreen to true;
  765.       hide button id 6;
  766.       hide button "Quit";
  767.     end;
  768.  
  769.     See Also: closePad, openPage
  770.  
  771.     -----------------------------------
  772.     DELETEBACKGROUND
  773.  
  774.     The deleteBackground message is sent to the current page right before a
  775.     background is deleted. You can only delete a background after all the
  776.     pages using it are deleted or cut.
  777.  
  778.     By intercepting this message, you control whether a background is
  779.     deleted. The following example allows a background to be deleted only if
  780.     the user's name is "John":
  781.  
  782.     handler deleteBackground;
  783.     begin
  784.       ask "What is your name?";
  785.       if it is "John" then pass;
  786.     end;
  787.  
  788.  
  789.  
  790.      _______________________________________________________________________
  791.                                  Chapter 1: What's Really Happening   88
  792.     ________________________________________________________________________
  793.  
  794.  
  795.     -----------------------------------
  796.     DELETEPAD
  797.  
  798.     This message is sent to the current page when the user selects Delete
  799.     Pad from the File menu. Since this message is sent before the pad is
  800.     deleted you can prevent deletion by intercepting this message.
  801.  
  802.     The following example makes a backup of the current pad (with the same
  803.     name as the current pad, but with a DEL file extension) before it is
  804.     deleted:
  805.  
  806.     handler deletePad;
  807.     begin
  808.       get the name of pad;
  809.       put ".DEL" after it;
  810.       record it & "{enter}";
  811.       playback;
  812.       doMenu "Save a Copy...";
  813.       pass;
  814.     end;
  815.  
  816.     -----------------------------------
  817.     DELETEPAGE
  818.  
  819.     The deletePage message is sent to a page when the user selects Delete or
  820.     Cut Page from the Edit menu. This message is sent before the page is
  821.     actually deleted. The page will only be deleted if this message is
  822.     received by HyperPAD. By intercepting deletePage, you prevent the page
  823.     from being deleted.
  824.  
  825.     The following handler intercepts deletePage to make sure that a linked
  826.     page gets deleted too. It first saves the current page, then gets a
  827.     linked page number from a field called "Attached Page Number". It then
  828.     goes to that page and deletes it.
  829.  
  830.     handler deletePage;
  831.     begin
  832.       get field "Attached Page Number";
  833.       push this page;
  834.       go to page "linked";
  835.       send "doMenu" "Delete Page" to this page;
  836.       pop page;
  837.       pass;
  838.     end;
  839.  
  840.  
  841.  
  842.      _______________________________________________________________________
  843.                                  Chapter 1: What's Really Happening   89
  844.     ________________________________________________________________________
  845.  
  846.  
  847.     The following handler intercepts deletePage to first make a copy of the
  848.     page in another pad called "backup":
  849.  
  850.     handler deletePage;
  851.     begin
  852.       doMenu "Copy Page";
  853.       push this page;
  854.       go to pad "backup";
  855.       doMenu "Paste Page";
  856.       pop page;
  857.       pass;
  858.     end;
  859.  
  860.     See Also: deletePad, deleteBackground
  861.  
  862.     -----------------------------------
  863.     DOMENU
  864.  
  865.     The doMenu message is sent to the current page when the user selects a
  866.     command from a menu. The exact text of the menu choice is sent with the
  867.     message as a parameter.  Intercepting doMenu is a powerful way to
  868.     customize HyperPAD. You can redefine the actions taken when a user
  869.     selects commands from the menu.
  870.  
  871.     The following example shows how to redefine the File Exit command. All
  872.     other menu commands will work normally.
  873.  
  874.     handler doMenu(command);
  875.     begin
  876.       if command is "Exit" then beep
  877.       else pass;
  878.     end;
  879.  
  880.     You can also select menu commands artificially, as is done in the
  881.     following handler in a button script:
  882.  
  883.     handler select;
  884.     begin
  885.       doMenu "Printer Setup...";
  886.       doMenu "Page Setup...";
  887.       doMenu "Print...";
  888.     end;
  889.  
  890.     Note:  The menu command must be represented exactly as it appears on
  891.     HyperPAD's menu.
  892.  
  893.  
  894.  
  895.      _______________________________________________________________________
  896.                                  Chapter 1: What's Really Happening   90
  897.     ________________________________________________________________________
  898.  
  899.  
  900.     -----------------------------------
  901.     HELP
  902.  
  903.     The help message is sent to the current page when the user presses F1 or
  904.     selects Help from the Go menu. By intercepting this message, you can
  905.     create your own help for your pads. If this message reaches HyperPAD,
  906.     HyperPAD's Help system will be loaded.
  907.  
  908.     In the following example, the user is asked which help is preferred, the
  909.     local (yours) or the main HyperPAD Help system:
  910.  
  911.     handler help;
  912.     begin
  913.       answer "Which help?" with "Local", "HyperPAD";
  914.       if it is "Local" then go to page "Local Help"
  915.       else pass;
  916.     end;
  917.  
  918.     You can send the help message from within a script in order to go to
  919.     HyperPAD's help:
  920.  
  921.     handler select;
  922.     begin
  923.       help;
  924.     end;
  925.  
  926.     -----------------------------------
  927.     IDLE
  928.  
  929.     This message is sent to the current page continuously when HyperPAD has
  930.     no other messages to pass and no other scripts are currently executing.
  931.     This message is only sent when the Browse tool is in use. Be cautious
  932.     when creating idle handlers. Since the idle message is sent so
  933.     frequently, the script will execute many times, greatly slowing down the
  934.     overall performance of your pad.
  935.  
  936.     A good use of the idle message is to display the time in a field. The
  937.     following handler in the pad script will do so (make sure you create a
  938.     background field named "time" before trying this):
  939.  
  940.     handler idle;
  941.     begin
  942.       put the time into field "time";
  943.     end;
  944.  
  945.  
  946.  
  947.      _______________________________________________________________________
  948.                                  Chapter 1: What's Really Happening   91
  949.     ________________________________________________________________________
  950.  
  951.  
  952.     Directly before the idle message is sent, the following actions are
  953.     performed:
  954.  
  955.     1.  The printerTranslation property is set to false.
  956.  
  957.     2.  The lockScreen property is set to false. If the previous value was
  958.     not false, then the screen is redrawn.
  959.  
  960.     3.  The lockRecent property is set to false.
  961.  
  962.     4.  The lockMessages property is set to false.
  963.  
  964.     5.  The numberForm at property is set back to its default: "0.######".
  965.  
  966.     6.  The visual effect is disabled.
  967.  
  968.     Note: If you have a runtime error in your idle handler, the only way to
  969.     fix it is to select "Script" in the runtime error box.
  970.  
  971.     -----------------------------------
  972.     KEYPRESS
  973.  
  974.     The keyPress message is sent directly to the page if a key is pressed
  975.     and no button or field has the focus. (This condition exists if the
  976.     mouse is clicked outside of all buttons and fields.) The key is passed
  977.     along with the message in its numeric format. The keyPress message is
  978.     only sent while the Browse tool is active.
  979.  
  980.     If you want a key on you keyboard to perform some action, regardless of
  981.     the current button or field, put a keyPress handler in the page.
  982.  
  983.     Be cautious when intercepting the keyPress message. You can easily lock
  984.     yourself out of HyperPAD. For example, the following handler in your pad
  985.     script makes your keyboard useless within HyperPAD:
  986.  
  987.     handler keypress(k);
  988.     begin
  989.     end;
  990.  
  991.     Since this handler does not pass the keyPress message on, the keyboard
  992.     will appear inactive. If you have a mouse, you will be able to access
  993.     and change the script, otherwise you will have to re-boot your machine
  994.     (by turning your machine off) and possibly lose some data. To safeguard
  995.     against this condition, you can create the following break handler in
  996.     every script containing a keyPress handler:
  997.  
  998.     handler break;
  999.     begin
  1000.       edit the script of me;
  1001.     end;
  1002.  
  1003.  
  1004.  
  1005.      _______________________________________________________________________
  1006.                                  Chapter 1: What's Really Happening   92
  1007.     ________________________________________________________________________
  1008.  
  1009.  
  1010.     Thus, if you made a mistake in your keyPress handler, you can always
  1011.     press CTRL+BREAK to edit the script.
  1012.  
  1013.     The following keyPress handler processes the F11, F12, and CTRL+V
  1014.     keystrokes, and passes any other keystroke up the object hierarchy:
  1015.  
  1016.     handler keypress(keyNumber);
  1017.     begin
  1018.       get key(keyNumber);
  1019.       case it of
  1020.         "f11" : go to page "help";
  1021.         "f12" : go to page "index";
  1022.         "ctrl+v" : ;
  1023.         otherwise : pass;
  1024.       end;
  1025.     end;
  1026.  
  1027.     See Also: key
  1028.  
  1029.     -----------------------------------
  1030.     MOUSEDOWN
  1031.  
  1032.     The mouseDown message is sent to the current page when the
  1033.     user presses the mouse button and the mouse pointer is not within the
  1034.     boundaries of any button or field. When the user releases the mouse
  1035.     button, the mouseUp messsage is sent.
  1036.  
  1037.     -----------------------------------
  1038.     MOUSESTILLDOWN
  1039.  
  1040.     The mouseStillDown message is sent to the current page continuously
  1041.     while the mouse button is held down. This message will be sent directly
  1042.     to the current page only if the mouse button was initially pressed
  1043.     outside of any buttons or fields.
  1044.  
  1045.     -----------------------------------
  1046.     MOUSEUP
  1047.  
  1048.     The mouseUp message is sent to the current page when the mouse button is
  1049.     released. This message will be sent directly to the current page only if
  1050.     the mouse button was initially pressed outside of any button or field's
  1051.     border.
  1052.  
  1053.     -----------------------------------
  1054.     NEWBACKGROUND
  1055.  
  1056.     The newBackground message is sent to the current page when a background
  1057.     is created. (This message is sent to the new page of the new background,
  1058.     not the page that was current when the New Background command was
  1059.     selected.) You can put a handler for the newBackground message either in
  1060.     the current pad script or the pad script of your Home pad.
  1061.  
  1062.  
  1063.  
  1064.      _______________________________________________________________________
  1065.                                  Chapter 1: What's Really Happening   93
  1066.     ________________________________________________________________________
  1067.  
  1068.  
  1069.     -----------------------------------
  1070.     NEWPAD
  1071.  
  1072.     The newPad message is sent to the new page of a pad after it is created.
  1073.     The only appropriate place for newPad handlers is in the pad script of
  1074.     the Home pad because new pads initially have no scripts.
  1075.  
  1076.     -----------------------------------
  1077.     NEWPAGE
  1078.  
  1079.     The newPage message is sent to a page when it is created, just after it
  1080.     appears on screen. This message is usually passed up the hierarchy,
  1081.     unless the page has been pasted and has a newPage handler.
  1082.  
  1083.     The following pad script names each new page according to the creation
  1084.     time and date.
  1085.  
  1086.     handler newPage;
  1087.     begin
  1088.       set the name of this page to date() && time();
  1089.     end;
  1090.  
  1091.     -----------------------------------
  1092.     OPENPAD
  1093.  
  1094.     The openPad message is sent to the default page of a newly opened pad,
  1095.     just after it is displayed. Use this message to perform any
  1096.     initialization that your pad may require, like the following example:
  1097.  
  1098.     handler openPad;
  1099.     begin
  1100.       global taxTotal,salesTotal;
  1101.       put 0 into taxTotal;
  1102.       put 0 into salesTotal;
  1103.       put empty into page field "first name";
  1104.       put 0.07 into page field "Sales Tax";
  1105.       hide page button 5;
  1106.     end;
  1107.  
  1108.     See Also: closePad, openPage, closePage
  1109.  
  1110.  
  1111.  
  1112.      _______________________________________________________________________
  1113.                                  Chapter 1: What's Really Happening   94
  1114.     ________________________________________________________________________
  1115.  
  1116.  
  1117.     -----------------------------------
  1118.     OPENPAGE
  1119.  
  1120.     The openPage message is sent to a page just after it becomes the current
  1121.     page.
  1122.  
  1123.     The following example uses openPage to set the focus to a default
  1124.     button:
  1125.  
  1126.     handler openPage;
  1127.     begin
  1128.       set the focus to page button "Pick";
  1129.     end;
  1130.  
  1131.     -----------------------------------
  1132.     QUIT
  1133.  
  1134.     This message is sent to the current page when the user selects Exit from
  1135.     the File menu. By intercepting this message, you can prevent the user
  1136.     from quitting HyperPAD. You can also send a quit message, causing
  1137.     HyperPAD to return to DOS.
  1138.  
  1139.     The following handler quits HyperPAD and returns to DOS:
  1140.  
  1141.     handler select;
  1142.     begin
  1143.       answer "Are you sure you want to quit?";
  1144.       if it is "Ok" then quit;
  1145.     end;
  1146.  
  1147.     The next example intercepts the quit message and goes to a pad called
  1148.     "phone" instead.
  1149.  
  1150.     handler quit;
  1151.     begin
  1152.       go to pad "phone";
  1153.     end;
  1154.  
  1155.     -----------------------------------
  1156.     RESUME
  1157.  
  1158.     The resume message is sent to the current page when HyperPAD resumes
  1159.     execution after running another program. After running other programs,
  1160.     HyperPAD will not complete execution of the script containing the run
  1161.     command. In the following example, the resume handler performs the
  1162.     actions that normally would not be executed after a run command:
  1163.  
  1164.  
  1165.  
  1166.      _______________________________________________________________________
  1167.                                  Chapter 1: What's Really Happening   95
  1168.     ________________________________________________________________________
  1169.  
  1170.  
  1171.     Put this handler in a button:
  1172.  
  1173.     handler select;
  1174.     begin
  1175.       run "C:\COMMAND.COM";
  1176.       beep;             -- this NEVER gets executed
  1177.     end;
  1178.  
  1179.     This handler belongs in the page:
  1180.  
  1181.     handler resume;
  1182.     begin
  1183.       beep;
  1184.     end;
  1185.  
  1186.     See Also: startUp, openPage, openPad
  1187.  
  1188.     -----------------------------------
  1189.     STARTUP
  1190.  
  1191.     The startUp message is sent to the first page displayed when HyperPAD is
  1192.     run for the first time that session.
  1193.  
  1194.     -----------------------------------
  1195.     SUSPEND
  1196.  
  1197.     This message is sent to the current page just before the user runs
  1198.     another program. This occurs when "Run Program" is selected from the
  1199.     File menu or the run command is executed in a script. By intercepting
  1200.     this message, you can prevent HyperPAD from launching other programs.
  1201.  
  1202.     In the following pad script, the suspend handler remembers the disk
  1203.     space so it can monitor how much space the launched program required:
  1204.  
  1205.     handler suspend;
  1206.     begin
  1207.       put the diskSpace into page field "saved disk space";
  1208.       pass;
  1209.     end;
  1210.  
  1211.     handler resume;
  1212.     begin
  1213.       get the diskSpace-page field "saved disk space";
  1214.       if it  0 then
  1215.         answer "Your program used" && it && "bytes";
  1216.     end;
  1217.  
  1218.  
  1219.  
  1220.      _______________________________________________________________________
  1221.                                  Chapter 1: What's Really Happening   96
  1222.     ________________________________________________________________________
  1223.  
  1224.  
  1225.     COMMON MESSAGE GROUPINGS
  1226.  
  1227.     Sometimes it is difficult to know what messages are being sent during
  1228.     common everyday operations. The following section describes some basic
  1229.     operations and the messages that HyperPAD sends.
  1230.  
  1231.     These messages are sent when the user starts HyperPAD:
  1232.  
  1233.     Message:                     Sent To:
  1234.     --------------------------------------------------------------
  1235.     startUp                      current page
  1236.  
  1237.     openPad                      current page
  1238.  
  1239.     openPage                     current page
  1240.  
  1241.     openButton/openField         current button or field
  1242.  
  1243.     These messages are sent when the user runs another program:
  1244.  
  1245.     Message:                     Sent To:
  1246.     --------------------------------------------------------------
  1247.     closeButton/closeField       current button or field
  1248.  
  1249.     closePage                    current page
  1250.  
  1251.     closePad                     current page
  1252.  
  1253.     suspend                      current page
  1254.  
  1255.     These messages are sent when the user returns from running another
  1256.     program:
  1257.  
  1258.     Message:                     Sent To:
  1259.     --------------------------------------------------------------
  1260.     resume                       current page
  1261.  
  1262.     openPad                      current page
  1263.  
  1264.     openPage                     current page
  1265.  
  1266.     openButton/openField         default button or field
  1267.  
  1268.     When the user presses the ESC key, these messages are sent:
  1269.  
  1270.     Message:                     Sent To:
  1271.     --------------------------------------------------------------
  1272.     keypress 283                 current object
  1273.  
  1274.     cancel                       current page
  1275.  
  1276.  
  1277.  
  1278.      _______________________________________________________________________
  1279.                                  Chapter 1: What's Really Happening   97
  1280.     ________________________________________________________________________
  1281.  
  1282.  
  1283.     When the key combination ALT+F5 is pressed, these messages are sent:
  1284.  
  1285.     Message:                     Sent To:
  1286.     --------------------------------------------------------------
  1287.     keyPress 27648               current object
  1288.  
  1289.     doMenu "Home"                current page
  1290.  
  1291.     When TAB is pressed to go one button to another button, these messages
  1292.     are sent:
  1293.  
  1294.     Message:                     Sent To:
  1295.     --------------------------------------------------------------
  1296.     closeButton                  current button
  1297.  
  1298.     openButton                   new current button
  1299.  
  1300.     When you press PGDN to go to the next page, these messages are sent:
  1301.  
  1302.     Message:                     Sent To:
  1303.     --------------------------------------------------------------
  1304.     keyPress 20736               current object
  1305.  
  1306.     doMenu "Next"                current page
  1307.  
  1308.     closeButton/closeField       current object
  1309.  
  1310.     closePage                    new current page
  1311.  
  1312.     openButton/openField         new current object
  1313.  
  1314.     When you click the mouse on a button, these messages are sent:
  1315.  
  1316.     Message:                     Sent To:
  1317.     --------------------------------------------------------------
  1318.     mouseUp                      current object
  1319.  
  1320.     select                       current object